from app.services.app_state_manager import AppStateManager
from app.services.state_types import StateType
from app.models.status_monitor_model import StatusMonitorModel, StatusType as MonitorStatusType

def _update_audio_output_status(self):
    """更新音频输出状态"""
    audio_service: AudioService = ServiceContainer.instance().get(AudioService)
    device_list = audio_service.get_output_devices()
    self.output_combo.clear()
    for device in device_list:
        self.output_combo.addItem(device)

    # 当前输出设备
    current_device = audio_service.get_current_output_device()
    if current_device and current_device in device_list:
        self.output_combo.setCurrentText(current_device)
        
    # 更新应用状态
    try:
        # 更新AppStateManager（保持与现有的兼容）
        try:
            AppStateManager.instance().set_state(StateType.AUDIO_OUTPUT, current_device)
        except Exception as e:
            logger.error(f"更新AppStateManager失败: {str(e)}")
        
        # 更新StatusMonitorModel
        try:
            StatusMonitorModel.instance().update_state(MonitorStatusType.AUDIO_OUTPUT, current_device)
        except Exception as e:
            logger.error(f"更新StatusMonitorModel失败: {str(e)}")
        
        logger.info(f"音频输出设备状态已更新: {current_device}")
    except Exception as e:
        logger.error(f"更新状态管理器失败: {str(e)}")
        import traceback
        logger.error(traceback.format_exc()) 